
local mt = require 'types.skill'.__index

function temp_skill(temp,name)
    local buff = ac.buff[name]
    buff.temp = temp
    return buff
end

--兼容被动端口
function mt:on_run(hero,target)
    self.target = target
    self:notify('on_cast_shot')
end


local unit = require 'types.unit'

--跳跃到指定点
function ac.unit.__index:jump(point,speed,height,func)
    local arc = 0.1
    if height<1 then
        arc = height
    end
    local mover = ac.mover('point'){
        mover = self,
        start = self,
        target = point,
        max_height = height,
        arc = arc,
        speed = speed,
        on_remove = func,
    }
    return mover
end

--向指定点/单位发射投射物
function ac.point.__index:launch_missile(target,model,speed,arc,func)
    local mover_class = target.type=='point' and target.type or 'target'
    local mover = ac.mover(mover_class){
        start = self,
        target = target,
        model = model,
        arc = arc,
        speed = speed,
        on_finish = func,
    }
    return mover
end

function ac.unit.__index:launch_missile(target,model,speed,arc,func)
    local start = self:get_launch_point()
    return start:launch_missile(target,model,speed,arc,func)
end

--向指定方向波
function ac.point.__index:launch_wave(model,angle,speed,distance,size,height)
    local mover = ac.mover('line'){
        start = self,
        angle = angle,
        model = model,
        speed = speed,
        height = height,
        size = size,
        distance = distance,
    }
    return mover
end

function ac.unit.__index:launch_wave(model,angle,speed,distance,size,height)
    local start = self:get_point()
    return start:launch_wave(model,angle,speed,distance,size,height)
end


--创建运动选取
function unit.__index:track_select(mover,area,time,func)
    local start = mover:get_point()
    local data = {}
    data.group = {}

    data.timer1 = ac.wait(time * 1000,function()
        data:remove()
    end)
    
    data.timer2 = ac.loop(30,function()
        local finish = mover:get_point()
        local angle = start / finish
        local range = start * finish
        local selector = ac.selector('unit'):enemy(self):filter(function(u)
            return data.group[u.handle]==nil
        end)
        if range>area then
            selector:line(start,angle,range + area/2,area*2)
        else
            selector:range(finish,area)
        end
        start = finish
        for u in selector:loop() do
            data.group[u.handle] = true
            func(u)
        end

    end)

    function data:remove()
        data.timer1:remove()
        data.timer2:remove()
    end

    function data:has(u)
        return data.group[u.handle]
    end

    return data
end



--贝塞尔曲线运动
function ac.point.__index:bezier_missile(target,center,model,speed,func)
    if type(center)=='table' then
        local point = self:get_point()
        local angle = point/target:get_point()
        local height = center[3] or self:get_height()
        if math.random(100)<=50 then
            center[1] = angle - center[1]
        else
            center[1] = angle + center[1]
        end
        center = self - center
        center.z = height + point:get_height()
    end
    ac.mover('bezier'){
        start = self,
        model = model,
        target = target,
        center = center,
        speed = speed,
        lock_range = 150,
        on_finish = func,
    }
end

function ac.unit.__index:bezier_missile(target,center,model,speed,func)
    local start = self:get_launch_point()
    start:bezier_missile(target,center,model,speed,func)
end
